package platform.service.ctx.ctxServer;

import platform.pubsub.AbstractSubscriber;
import platform.service.ctx.ctxChecker.CheckerStarter;
import platform.service.ctx.item.ItemManager;
import platform.service.ctx.pattern.PatternManager;
import platform.service.ctx.rule.RuleManager;
import platform.service.ctx.statistics.ServerStatistics;

import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;


public abstract class AbstractCtxServer extends AbstractSubscriber implements Runnable{
    protected Thread sender;
    protected Thread processor;

    protected ConcurrentLinkedQueue<Map.Entry<String, String>> msgBuffer;

    protected PatternManager patternManager;

    protected RuleManager ruleManager;

    protected ItemManager itemManager;

    protected ChangeGenerator changeGenerator;

    protected CheckerStarter checker;

    protected CtxFixer ctxFixer;

    protected ServerStatistics serverStatistics;


    public abstract void init();

    public void start() {
        if (sender == null) {
            sender = new Thread(this, getClass().getName());
            sender.start();
        }
    }

    public void restart() {
        sender = new Thread(this, getClass().getName());
        sender.start();
    }


    public PatternManager getPatternManager() {
        return patternManager;
    }

    public RuleManager getRuleManager() {
        return ruleManager;
    }

    public ItemManager getItemManager() {
        return itemManager;
    }

    public ChangeGenerator getChangeGenerator() {
        return changeGenerator;
    }

    public CheckerStarter getChecker() {
        return checker;
    }

    public CtxFixer getCtxFixer() {
        return ctxFixer;
    }

    public ServerStatistics getServerStatistics() {
        return serverStatistics;
    }
}
